import React, {Component} from 'react';
import {Link} from "react-router-dom";
import {UserOutlined} from '@ant-design/icons';
import {Form, Input, Button, Checkbox, Card, message} from "antd";
import {setToken} from "../../utils/auth";
import "./login.css";

function Login(props) {
    const layout = {
        labelCol: {span: 8},
        wrapperCol: {span: 16},
    };
    const tailLayout = {
        wrapperCol: {offset: 8, span: 16},
    };

    const onFinish = values => {
        console.log('Success:', values);
        setToken(values.username);
        props.history.push("/admin");
    };

    const onFinishFailed = errorInfo => {
        console.log('Failed:', errorInfo);
    };

    const handleSubmit = e => {
        e.preventDefault();
        props.form.validateFields((err, values) => {
            if (!err) {
                console.log("Received values of form: ", values);
                // setToken(values.username);
                // props.history.push("/admin");
                /*             loginApi({
                                 userName: values.username,
                                 password: values.password
                             })
                                 .then(res => {
                                     if (res.code === "success") {
                                         message.success("登录成功");
                                         setToken(res.token);
                                         props.history.push("/admin");
                                     } else {
                                         message.info(res.message);
                                     }
                                     // console.log(res);
                                 })
                                 .catch(err => {
                                     // console.log(err);
                                     message.error("用户不存在");
                                 });*/
            }
        });
    };
    return (
        <Card title="QF Admin SYS" className="login-form">
            <Form
                {...layout}
                name="basic"
                initialValues={{
                    remember: true,
                    username:'wxq',
                    password:'111111'
                }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
            >
                <Form.Item
                    label="Username"
                    name="username"
                    rules={[{required: true, message: 'Please input your username!'}]}
                >
                    <Input/>
                </Form.Item>

                <Form.Item
                    label="Password"
                    name="password"
                    rules={[{required: true, message: 'Please input your password!'}]}
                >
                    <Input.Password/>
                </Form.Item>

                <Form.Item {...tailLayout} name="remember" valuePropName="checked">
                    <Checkbox>Remember me</Checkbox>
                </Form.Item>

                <Form.Item {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                </Form.Item>
            </Form>
        </Card>
    );
}

export default Login
